package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.api.ApiFacadeMethodBo;
import com.cw.jeeyt.dao.model.api.ApiFacadeMethodDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * api接口方法转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiFacadeMethodConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiFacadeMethodBo do2Bo(ApiFacadeMethodDo model) {
        if (model == null) {
            return null;
        }
        ApiFacadeMethodBo bo = new ApiFacadeMethodBo();
        bo.setId(model.getId());
        bo.setDocId(model.getDocId());
        bo.setApiFacadeCode(model.getApiFacadeCode());
        bo.setMethodCode(model.getMethodCode());
        bo.setMethodName(model.getMethodName());
        bo.setMethodType(model.getMethodType());
        bo.setRequest(model.getRequest());
        bo.setRequestIds(model.getRequestIds());
        bo.setResponse(model.getResponse());
        bo.setResponseIds(model.getResponseIds());
        bo.setPublicObj(model.isPublicObj());
        bo.setUseMethod(model.getUseMethod());
        bo.setMethodContentAnalysis(model.getMethodContentAnalysis());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiFacadeMethodDo bo2Do(ApiFacadeMethodBo bo) {
        if (bo == null) {
            return null;
        }
        ApiFacadeMethodDo model = new ApiFacadeMethodDo();
        model.setId(bo.getId());
        model.setDocId(bo.getDocId());
        model.setApiFacadeCode(bo.getApiFacadeCode());
        model.setMethodCode(bo.getMethodCode());
        model.setMethodName(bo.getMethodName());
        model.setMethodType(bo.getMethodType());
        model.setRequest(bo.getRequest());
        model.setRequestIds(bo.getRequestIds());
        model.setResponse(bo.getResponse());
        model.setResponseIds(bo.getResponseIds());
        model.setPublicObj(bo.isPublicObj());
        model.setUseMethod(bo.getUseMethod());
        model.setMethodContentAnalysis(bo.getMethodContentAnalysis());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiFacadeMethodBo> doList2BoList(List<ApiFacadeMethodDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiFacadeMethodConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiFacadeMethodDo> boList2DoList(List<ApiFacadeMethodBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiFacadeMethodConverter::bo2Do));
    }
}